package com.guxingke.typecho4j.jfinal.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;

/**
 * typecho_options表 对应的model
 * */
public class Option extends Model<Option> {
	private static final long serialVersionUID = -1772123323257332875L;

	public static final Option dao = new Option();

	public List<Option> findAll() {
		String sql = "select * from typecho_options";
		return dao.find(sql);
	}

	public String getValue(String key) {
		String sql = "select value from typecho_options where name = ?";
		return findFirst(sql, key).getStr("value");
	}

	public boolean setValue(Option option) {
		boolean result = false;
		Option temp = findById(option.get("name"));
		if (temp != null) {
			result = option.update();
		} else {
			result = option.save();
		}
		return result;
	}
}
